<include file="Public/header" />
<include file="Public/menu" />

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            权限
            <small>设置</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 权限设置</a></li>
            <li class="active">用户</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content"><div class="row"><div class="col-md-12"><div class="box">
        <div class="box-header">
            <h3 class="box-title">账号</h3>

            <div class="form-inline pull-right">
                <form action="/admin/auth/roles" method="get" pjax-container="">
                    <fieldset>
                        <div class="input-group input-group-sm">
                            <span class="input-group-addon"><strong>Id</strong></span>
                            <input type="text" class="form-control" placeholder="Id" name="id" value="">
                        </div>

                        <div class="input-group input-group-sm">
                            <div class="input-group-btn">
                                <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
                            </div>
                        </div>

                    </fieldset>
                </form>
            </div>

            <div class="btn-group pull-right" style="margin-right: 10px">
                <a href="{:U('admin/rbac/userAdd')}" class="btn btn-sm btn-success"><i class="fa fa-save"></i>&nbsp;&nbsp;新增</a>
            </div>

        </div>
        <!-- /.box-header -->
        <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
                <tbody>
                <tr>
                    <th><input type="checkbox" class="grid-select-all"></th>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>角色</th>
                    <th>操作</th>
                </tr>
                <?php foreach($user as $v){ ?>
                <tr>
                    <td><input type="checkbox" class="grid-item" data-id="1"></td>
                    <td>{$v['id']}</td>
                    <td>{$v['username']}</td>
                    <td>
                        <?php echo $v['type']==1 ? '超级管理员' : $v['name'];?>
                    </td>
                    <td>
                        <a href="{:U('rbac/userEdit',array('id'=>$v['id']))}"><i class="fa fa-edit"></i></a>
                        <?php if ($v['type']==2) { ?>
                        <a onclick="if(confirm('确定删除?')==false)return false;" href="{:U('rbac/userDel',array('id'=>$v['id']))}" data-id="31" class="_delete"><i class="fa fa-trash"></i></a>
                        <?php } ?>
                    </td>
                </tr>
                <?php } ?>
                </tbody>
            </table>
        </div>
        <div class="box-footer clearfix">
            <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;

            <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>

            {$page}
        </div>

        <!-- /.box-body -->
    </div></div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />
<script data-exec-on-popstate>

    $(function () {

        $('.grid-select-all').change(function() {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('.batch-delete').on('click', function() {
            var selected = [];
            $('.grid-item:checked').each(function(){
                selected.push($(this).data('id'));
            });

            if (selected.length == 0) {
                return;
            }

            if(confirm("Are you sure to delete this item ?")) {
                $.post('/admin/auth/roles/' + selected.join(), {_method:'delete','_token':'ALpaP7hXZ6s2dnAdE02Z6mUSHPt8RkYbcDRp6rpw'}, function(data){
                    $.pjax.reload('#pjax-container');
                    noty({
                        text: "<strong>Succeeded!</strong>",
                        type:'success',
                        timeout: 1000
                    });
                });
            }
        });
    });
</script>

